var downLink = "";
var videoLong;
function myDownloadfile(a,b,c) {
    $("#table").addClass("el-loading");
    downloadfile(a,b,c);
    setTimeout(function (){
        $("#table").removeClass("el-loading");
    },videoLong);
}
$(()=>{
    let $get = $("#get");
    let $inputbox = $("#inputbox");
    $inputbox.focus();
    let $main = $("#main");
    let $table = $("#table");
    let $video_title = $("#video_title");
    let $video_description = $("#video_description");
    let $video_cover = $("#video_cover");
    let $video_play = $("#video_play");
    let $video_link = $("#video_link");
    $inputbox.keydown(e=>{if (e.keyCode===13)$get.click();});
    $(document).keydown(e=>{if(e.keyCode===36){if(e.ctrlKey){if(confirm("是否要返回上一页？")){location.href = "./?/index";}}else{if(confirm("是否要返回首页？")){history.back();}}}});
    $get.click(()=>{
        $main.addClass("el-loading");
        let link = $inputbox.val();
        $.post("#",{
            link:link
        },text=>{
            $main.removeClass("el-loading");
            $table.hide();
            $table.removeClass("el-loading");
            let data = JSON.parse(text);
            if (data["code"]===1){
                let title = data["data"]["title"];
                videoLong=data["data"]["list"][0]["duration"]*100;
                $video_title.text(title);
                $video_description.text(data["data"]["desc"]);
                $video_cover.html(`<img src="${data["data"]["cover"]}" width="400" alt="视频封面">`);
                downLink = data["data"]["list"][0]["url"];
                $video_play.html(`<video src="${downLink}" controls width="400">`);
                $video_link.html(`<a class="btn btn-lg btn-flat waves-light waves-button waves-effect" onclick="myDownloadfile(downLink,'${title}.mp4',getFileType('${title}.mp4'))">下载</a>`);
                loadColor();
                $table.fadeIn();
            }else if(data["code"]===0) {
                alert(data["msg"]);
            }
            console.log(text);
        });
    });
});
